<?php
	
	require_once 'Exception.php';
	require_once 'PHPMailer.php';
	require_once 'SMTP.php';
	use PHPMailer\PHPMailer\PHPMailer;
	use PHPMailer\PHPMailer\SMTP;
	use PHPMailer\PHPMailer\Exception;

	class sendMail{

		public static $HOST = 'smtp.qq.com';   //QQ 邮箱的服务器地址
		public static $PORT = 587;             //smtp 服务器的远程服务器端口号
		public static $SMTP = 'SSL';           //使用 ssl 加密方式
		public static $CHARSET = 'UTF-8';      //设置发送的邮件的编码

		private static $USERNAME = '2258162185@qq.com'; // 授权登录的账号
    private static $PASSWORD = 'cswovhdciuljdhhd'; // 授权登录的密码
    private static $NICKNAME = '沙漠之狐(胡)'; // 发件人的昵称

		public function  __construct($debug = false){
			$this->mail = new PHPMailer(true);
			$this->mail->SMTPDebug = $debug ? 2 : 0;
			$this->mail->isSMTP();
		}
		
		public function getPHPMailer(){
			return $this->mail;
		}

		private function loadConfig(){
			
      $this->mail->SMTPAuth = true; // 开启 SMTP 认证
      $this->mail->Host = self::$HOST; // SMTP 服务器地址
      $this->mail->Port = self::$PORT; // 远程服务器端口号
      $this->mail->SMTPSecure = self::$SMTP; // 登录认证方式
      
      $this->mail->Username = self::$USERNAME; // SMTP 登录账号
      $this->mail->Password = self::$PASSWORD; // SMTP 登录密码
      $this->mail->setFrom(self::$USERNAME, self::$NICKNAME);
      
      $this->mail->isHTML(true); // 邮件正文是否为 HTML
      $this->mail->CharSet = self::$CHARSET; // 发送的邮件的编码

		}

		public function addFile($path){
			$this->mail->addAttachment($path);
		}

		public function send($addressee, $title, $content){
			$this->loadConfig();
			$this->mail->addAddress($addressee);
			$this->mail->Subject = $title;
			$this->mail->Body = $content;
			return $this->mail->send();
		}

	}

	
?>